<%@page import="com.tiantian.domain.Businessstore"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<!DOCTYPE>
<html>
<head>
<style type="text/css">
.update {
	font-size: 12px;
	padding-left: 15px;
	color: #0033FF;
}
</style>
<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>"
	type="text/javascript"></script>
<script type="text/javascript"
	src="<c:url value='/static/common/uc_message.js'/>"></script>
<!-- validate -->
<link rel="stylesheet" href="<c:url value='/static/themes/bootstrap/bootstrapValidator.min.css'/>" />
<script type="text/javascript" src="<c:url value='/static/themes/bootstrap/bootstrapValidator.min.js'/>"></script>
<title>员工信息</title>
</head>
<body>
	<div class="col-lg-12">
		<div id="message"></div>
		<div class="panel panel-default bk-bg-white">
			<div class="panel-heading bk-bg-white">
				<h4>员工信息</h4>
			</div>
			<div class="panel-body">
				<div class="form-group col-sm-12">
					<div class="col-sm-12">
						<form class="form-horizontal" id="userForm">
							<div class="panel panel-default">
								<div class="panel-body">
									<input type="hidden" name="id" value="${user.id }">
									<div class="form-group">
										<label class="col-sm-2 control-label"><code style="">*&nbsp;</code>账号名:</label>
										<div class="col-sm-5">
											<input type="text" class="form-control" name="username"
												placeholder="账号名" value="${user.username }">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-2 control-label"><code style="">*&nbsp;</code>密码:</label>
										<div class="col-sm-5">
											<input type="password" class="form-control" name="password"
												placeholder="密码" value="${user.password }">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-2 control-label"><code style="">*&nbsp;</code>确认密码:</label>
										<div class="col-sm-5">
											<input type="password" class="form-control" name="newPassword"
												placeholder="确认密码" value="${user.password }">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-2 control-label"><code style="">*&nbsp;</code>角色:</label>
										<div class="col-sm-8">
											<c:forEach items="${roles }" var="role" varStatus="status">
												<c:if test="${status.index%3==0 }">
													<div class="checkbox block">
												</c:if>
													<label class="col-sm-4"><input type="checkbox" name="check_${role.id }"  ${empty userRole[role.id]?"":"checked='checked'"}> ${role.name }</label> 
												<c:if test="${status.index%3==2 }">
													</div>
												</c:if>
											</c:forEach>
										</div>
									</div>
								</div>

								<div class="panel-heading">
									<h4 class="panel-title">其他信息</h4>
								</div>
								<div class="panel-body">
									<div class="form-group">
										<label class="col-sm-2 control-label">名字:</label>
										<div class="col-sm-5">
											<input type="text" class="form-control" name="nickName"
												placeholder="名字" value="${user.nickName }">
										</div>
									</div>

									<div class="form-group">
										<label class="col-sm-2 control-label">邮箱:</label>
										<div class="col-sm-5">
											<input type="email" class="form-control" name="email"
												placeholder="邮箱" value="${user.email }">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">电话:</label>
										<div class="col-sm-5">
											<input type="text" class="form-control" name="phone"
												placeholder="电话" value="${user.phone }">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">工作QQ:</label>
										<div class="col-sm-5">
											<input type="text" class="form-control" name="qq"
												placeholder="工作QQ" value="${user.qq }">
										</div>
									</div>
									<div class="form-group">
										<label class="col-sm-2 control-label">工作微信:</label>
										<div class="col-sm-5">
											<input type="text" class="form-control" name="weixin"
												placeholder="工作微信"  value="${user.weixin }">
										</div>
									</div>
								</div>
								<!-- panel-body -->
								<div class="panel-footer">
									<div class="form-group " style="text-align: center;">
										<button type="button" id="unsave"
											class="btn btn-default btn-sm" style="width: 150px">取消</button>
										<button type="button" id="save" class="btn btn-warning btn-sm"
											style="width: 150px">保存</button>
									</div>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script type="text/javascript">
		$(function($) {
			//验证框架
			$('#userForm').bootstrapValidator({
				message : '这个值未通过验证',
				feedbackIcons : {
					valid : 'glyphicon glyphicon-ok',
					invalid : 'glyphicon glyphicon-remove',
					validating : 'glyphicon glyphicon-refresh'
				},
				fields : {
					username : {
						validators : {
							notEmpty: {
		                        message: '登录账号是必须的不能为空'
		                    },
		                    stringLength: {
		                        min: 6,
		                        max: 30,
		                        message: '登录账号长度在6-30位'
		                    }
						}
					},
					password: {
						validators : {
							notEmpty: {
		                        message: '密码是必须的不能为空'
		                    },
		                    stringLength: {
		                        min: 6,
		                        max: 50,
		                        message: '密码长度在6-50位'
		                    },
						}
					},
					newPassword:{
						validators : {
							notEmpty: {
		                        message: '密码是必须的不能为空'
		                    },
		                    stringLength: {
		                        min: 6,
		                        max: 50,
		                        message: '密码长度在6-50位'
		                    },
						}
					},
					nickName:{
						validators : {
		                    stringLength: {
		                        max: 50,
		                        message: '名称最大长度不超过50'
		                    },
						}
					},
					email:{
						validators : {
		                    stringLength: {
		                        max: 200,
		                        message: '名称最大长度不超过200'
		                    },
		                    emailAddress: {
		                        message: '请输入邮箱格式'
		                    }
						}
					},
					phone:{
						validators : {
		                    stringLength: {
		                        max: 100,
		                        message: '名称最大长度不超过100'
		                    }
						}
					},
					qq:{
						validators : {
		                    stringLength: {
		                        max: 30,
		                        message: '名称最大长度不超过30'
		                    }
						}
					},
					weixin:{
						validators : {
		                    stringLength: {
		                        max: 100,
		                        message: '名称最大长度不超过100'
		                    }
						}
					}
				}
			}).on('success.form.bv', function(e) {
				$.blockUI({ message: '加载中...' });
				$.ajax({
					type : "post",
					url : path + "/auth/user/saveUser?_t"+new Date().getTime(),
					cache : false,
					data : $('#userForm').serialize(),
					dataType : "json",
					success : function(data) {
						showmessage(data.msg, function() {
							if(data.success){
								location.reload(true);
							}else{
								$.unblockUI();
							}
						});
					}
				});
			});
			
			
			//保存
			$('#save').click(function() {
				$('#userForm').bootstrapValidator('validate');
			});
			//取消
			$('#unsave').click(function() {
				window.location.href = path + "/auth/user/index?_t="+new Date().getTime();
			});
			
			//显示消息
			function showmessage(msg, callback, msgId) {
				if (msgId) {
					$('#' + msgId).ucMessage({
						msg : msg,
						callback : callback
					});
				} else {

					$('#message').ucMessage({
						msg : msg,
						callback : callback
					});
				}
			} 
		});
	</script>
</body>

</html>